import Vue from 'vue'
import Vuex from 'vuex'
import persist from "vuex-persistedstate"


Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    list: [],
    dizhiList:[]
  },
  mutations: {
    //搜索
    enter(state, title) {
      if(title == ' ' || title == ''){
         return false
      }
      if (!state.list.includes(title) ) {
        state.list.unshift(title)
      } else {
        let i = state.list.indexOf(title)
        state.list.splice(i, 1)
        state.list.unshift(title)
      }
    },
    sc(state) {
      state.list = []
    },
    scs(state,i){
      state.list.splice(i,1)
    },

    //地址管理
    adddizhi(state,obj){
     console.log(obj);
     state.dizhiList.push(obj)
     console.log(state.dizhiList);
    },
    //地址 删除
    remove(state,id){
      state.dizhiList.forEach((item,i) => {
       if(item.id == id){
         state.dizhiList.splice(i,1)
       }
     console.log(item,i);
      })
    }
  },
  actions: {

  },
  modules: {
  },
  plugins: [
    persist({
      storage:localStorage,
      // key: "history"
    })
  ]

})
